package com.chuangke.common.utils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Base64;

import net.coobird.thumbnailator.Thumbnails;

public class ImageCompressor {

	/**
	 * 图片压缩到指定大小
	 * 
	 * @param origPicContent
	 * @param desFileSize
	 * @return
	 */
	public static String compressPic(String origPicContent) {
		ByteArrayInputStream in = null;
		ByteArrayOutputStream out = null;
		byte[] bytes = Base64.getDecoder().decode(origPicContent);
		in = new ByteArrayInputStream(bytes);
		out = new ByteArrayOutputStream();
		try {
			Thumbnails.of(in).size(100, 100).scale(0.8f)
					.toOutputStream(out);
			bytes = out.toByteArray();
			return Base64.getEncoder().encodeToString(bytes);
		} catch (IOException e) {
			e.printStackTrace();
			return origPicContent ;
		}
		
	}
}
